package com.LFLWZ.controller;

import com.LFLWZ.beans.Dto.Dto;
import com.LFLWZ.beans.POJO.ClassroomCourse;
import com.LFLWZ.beans.Vo.ClassroomCourseVo;
import com.LFLWZ.service.ClassroomCourseService;
import com.LFLWZ.utils.DtoUtil;
import com.LFLWZ.utils.EmptyUtils;
import com.LFLWZ.utils.MinioUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("home")
public class home {

    @Reference(timeout = 40000)
    private ClassroomCourseService classroomCourseService;

    @PostMapping("courseInsert")
    public Dto courseInsert(@RequestBody ClassroomCourseVo classroomCourse){
        System.out.println("试试");
        Dto dto=null;
        System.out.println(classroomCourse.getImgurl());
        if (EmptyUtils.isEmpty(classroomCourse)){
            dto= DtoUtil.returnError(4001,"数据格式错误");
        }
        ClassroomCourseVo classroomCourse1=classroomCourseService.insert(classroomCourse);
        if (EmptyUtils.isEmpty(classroomCourse1)){
            dto=DtoUtil.returnError(4002,"数据新增失败");
        }else {
            dto=DtoUtil.returnSuccessData(classroomCourse1);
        }
        return dto;
    }

    /**
     * 上传图片
     */
    @PostMapping("uploadImage")
    public Dto uploadImage(@RequestParam(value = "file") MultipartFile file){
        System.out.println(file);
        String url=MinioUtil.uploadImage(0, file);
        return DtoUtil.returnSuccessData(url);
    }
}
